package com.example.myfirstapplication.receiver

import android.app.AlertDialog
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.example.myfirstapplication.LoginActivity
import com.example.myfirstapplication.utils.ActivityCollector
import com.example.myfirstapplication.utils.MyApplication
import com.example.myfirstapplication.utils.goActivity

class OffLineRecevier : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        AlertDialog.Builder(context).apply {
            setTitle("提醒：")
            setMessage("你确定要强行退出么？")
            setCancelable(false)
            setPositiveButton("确定") { dialog, which ->
                ActivityCollector.finishAll()
                val passwordSPF =
                    MyApplication.context.getSharedPreferences("password", Context.MODE_PRIVATE)
                passwordSPF.edit().clear().commit()
                goActivity(context, LoginActivity::class.java)
            }
            show()
        }
    }
}